home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94a.txt / 000183_icon-group-sender _Tue Jun 21 11:27:52 1994.msg < prev    next >
Internet Message Format  |  1994-08-19  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Tue, 21 Jun 1994 06:40:56 MST
  2. Message-Id: <m0qG32b-000BzQC@bootes.cus.cam.ac.uk>
  3. X-Sender: jdg1002@pop.cus.cam.ac.uk
  4. Mime-Version: 1.0
  5. Content-Type: text/plain; charset="us-ascii"
  6. Date: Tue, 21 Jun 1994 11:27:52 +0100
  7. To: icon-group@cs.arizona.edu
  8. From: Jason Grossman <Jason.Grossman@ucs.cam.ac.uk>
  9. Subject: Re: anti-ugly contest
  10. Status: R
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12.  
  13. >Help stamp out ugly icon code!
  14. >
  15. >I'm getting better.  My first ugly version of the following routine,
  16. >produced after much trial and error, required two (count 'em!) extra
  17. >variables.  After some inspection, I managed to reduce it to:
  18. >
  19. >        procedure squeeze(s)
  20. >           # Squeze out excess blanks from inside a string
  21. >           s2 := ""
  22. >           s ? {
  23. >             while s2 ||:= tab(upto(" ")+1) do tab(many(" "))
  24. >             s2 ||:= tab(0)
  25. >             }
  26. >           return s2
  27. >        end
  28. >
  29. >That cut the number of extra variables down to one (s2).
  30. >Question: Is there an even more elegant way to do this that requires
  31. >no extra variables?
  32.  
  33.  
  34. I do it using a replace procedure, so I could say
  35.  
  36. procedure squeeze (s)
  37.  
  38.         s := replace (" ", "", s)
  39.  
  40. end
  41.  
  42. and replace is defined by
  43.  
  44. procedure replace (a, b, s)
  45.  
  46.         /s := \&subject  # in case we're doing pattern matching
  47.         while (s [find (a, s)+:*a] := b)
  48.         return s
  49.  
  50. end
  51.  
  52.  
  53. Is this inefficient? (Be lenient. I'm a beginner.)
  54.  
  55. Jason
  56.  
  57.  
  58.